<template>
    <!-- pages/setpaypassword/index.wxml -->
    <view class="pages">
        <view class="mt-20">请输入新的支付密码</view>
        <padinput class="mt-20" id="padinput" @infotan="getnewpassword($event, { tagId: 'padinput' })"></padinput>
        <view class="mt-20">再次输入新的支付密码</view>
        <padinput class="mt-20" @infotan="getnewpasswordcoyp" :Value="newpasswordcoyp"></padinput>
        <button class="btn-area" @tap="toConfirm">确定</button>
    </view>
</template>

<script>
// pages/setpaypassword/index.js
const app = getApp(); // 引入app

import _request from '../../utils/request.js';
export default {
    data() {
        return {
            imgUrl: app.globalData.imgUrl,
            //全局img路径
            newpassword: '',
            newpasswordcoyp: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        // 获取新密码
        getnewpassword(e, _dataset) {
            /* ---处理dataset begin--- */
            this.datasetHandle(e, _dataset);
            /* ---处理dataset end--- */
            this.setData({
                newpassword: e.detail.inputValue
            });
        },

        // 获取新密码
        getnewpasswordcoyp(e) {
            this.setData({
                newpasswordcoyp: e.detail.inputValue
            });
        },

        //
        toConfirm() {
            _request
                .postObj('/settings/setPaypassword', {
                    copyPayword: this.newpasswordcoyp,
                    payword: this.newpassword,
                    userId: uni.getStorageSync('userid')
                })
                .then((res) => {
                    if (res.data.code === 200) {
                        uni.showToast({
                            title: '支付密码设置成功',
                            icon: 'none',
                            duration: 500
                        });
                        setTimeout(() => {
                            uni.navigateBack({
                                delta: 1
                            });
                        }, 500);
                    } else {
                        uni.showToast({
                            title: res.data.message || '支付密码设置失败!',
                            icon: 'none',
                            duration: 2000
                        });
                        this.setData({
                            newpasswordcoyp: ''
                        });
                    }
                })
                .catch((error) => {
                    console.log(error);
                });
        }
    }
};
</script>
<style>
/* pages/setpaypassword/index.wxss */

.pages {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-area {
    margin-top: 100rpx;
    width: 670rpx;
    height: 88rpx;
    background: #ff8722;
    border-radius: 44rpx;
    font-size: 32rpx;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #ffffff;
    line-height: 88rpx;
    text-align: center;
}
</style>
